﻿@model WebshopHPWcore.Models.WishListViewModels.WishListViewModel
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
@{
    ViewBag.Title = "Wenslijst";
}
@functions
{
    public string GetAntiXsrfRequestToken()
    {
        return Xsrf.GetAndStoreTokens(Context).RequestToken;
    }
}

@section Scripts {
    <script type="text/javascript">
        $(function () {
            // Document.ready -> link up remove event handler
            $(".RemoveLink").click(function () {
                // Get the id from the link
                var recordToDelete = $(this).attr("data-id");
                var PostToUrl = $(this).attr("data-url");
                if (recordToDelete != '') {

                    // Perform the ajax post
                    $.ajax(PostToUrl, {
                        type: "post",
                        data: {
                            "id": recordToDelete
                        },
                        dataType: "json",
                        headers: {
                            "RequestVerificationToken": '@GetAntiXsrfRequestToken()'
                        }
                    }).done(function (data) {
                        // Successful requests get here
                        // Update the page elements
                        if (data.itemCount == 0) {
                            $('#row-' + data.deleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.deleteId).text(data.itemCount);
                        }
                        
                        $('#update-message').text(data.message);
                    });
                }
            });
        });
    </script>
}

<br />

<h2>Wenslijst</h2>
<br />
<div id="update-message">
</div>
<table id="cart-summary" class="table table-bordered table-responsive table-hover table-striped">
    <tr></tr>
    @foreach (var item in Model.WishListItems)
    {
        <tr id="row-@item.WishListItemId">
            <td width="300">
                @if (item.Car.color == "Wit")
                { <img src="~/images/auto1.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Zilver")
                { <img src="~/images/auto2.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Grijs")
                {  <img src="~/images/auto3.jpg" alt="Visual Studio" class="img-responsive" />     }
                @if (item.Car.color == "Rood")
                { <img src="~/images/auto4.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Blauw")
                { <img src="~/images/auto5.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Zwart")
                {  <img src="~/images/auto6.jpg" alt="Visual Studio" class="img-responsive" />     }
                @if (item.Car.color == "Geel")
                { <img src="~/images/auto7.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Oranje")
                { <img src="~/images/auto8.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Groen")
                {  <img src="~/images/auto9.jpg" alt="Visual Studio" class="img-responsive" />     }
            </td>
            <td>
                <p class="Text-size">
                    @item.Car.brand @item.Car.model
                </p>
                @if (item.Car.Count >= 1)
                { 
                <p>€  @item.Car.price ,-</p>
                }
                @if (item.Car.Count < 1)
                {
                    <p>Dit product is verkocht en niet meer beschikbaar.</p>
                }

            </td>
            <td id="item-count-@item.WishListItemId">
                Aantal: @item.Count
            </td>
            <td>
                <a asp-controller="WishList" asp-action="Details" asp-route-id="@item.carid" class="btn btn-default" style="float:right">Details</a>
                <br />
                <br />
                <a asp-controller="ShoppingCart" asp-action="AddToCart" asp-route-id="@item.carid" class="btn btn-default" style="float:right;background-color:#26B226;border-color:#187018"><i class="fa fa-cart-plus" style="font-size:20px;color:white;"></i></a>
                <br />
                <br />
                <a href="#" class="btn btn-default RemoveLink" style="float:right;background-color:#F04C33" data-id="@item.WishListItemId"
                   data-url='@Url.Content("~/WishList/RemoveFromCart")'><i class="fa fa-trash" aria-hidden="true" style="font-size:24px;"></i></a>
            </td>
        </tr>
    }

</table>
<br />
<br />